<!--
* description: 车辆管理-库存明细查询
* author: ligy
* createdDate: 2020-11-18
-->
<template>
  <div class="app-container app-container-table">
    <one-table-template
      ref="multipleTable"
      :dynamic-buttons="tableButtons"
      :dynamic-components="tableComponents"
      :dynamic-api-config="dynamicApiConfigs"
      :dynamic-table-cols="tableCols"
      :dynamic-form-fields="formField"
      :dynamic-is-show-select="false"
      :dynamic-is-init-table="true"
      :dynamic-is-fix-choose="false"
      :dynamic-is-fix-index="false"
      :dynamic-api-style="'restful'"
    />
  </div>
</template>

<script>
import { oneTableWithViewTemplateMixins } from '@/components/mixins/oneTableWithViewTemplateMixins'
import OneTableTemplate from '@/components/templates/oneTable'
import Vue from 'vue'
// import { exportExcel } from '@/utils/export.js'
import api from '@/api/vehicleManagement'
import lov from '@/api/Lov'

export default {
  name: 'InventoryDetailsInquiry',
  components: {
    OneTableTemplate
  },
  mixins: [oneTableWithViewTemplateMixins],
  // 阻塞路由预加载网格中组件的数据
  beforeRouteEnter(to, from, next) {
    Vue.prototype.$ConfigCache.CacheConfig.initData([to.path, 'supplierMessage-edit'], () => {
      next()
    })
  },
  data() {
    // 页面标识（与上面beforeRouteEnter中的对应）
    const viewPageCode = this.$route.path
    // 绑定事件配置化事件
    this.$ConfigCache.CacheConfig.bindEvent(this, [viewPageCode])
    return {
      dynamicApiConfigs: api.inventoryDetailsInquiry,
      // 动态生成网格列
      tableCols: this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          .length > 0
        ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
        : [
          {
            prop: 'vin',
            label: 'VIN'
          },
          {
            prop: 'lastInStockDate',
            label: '总部入库时间'
          },
          {
            prop: 'moveStateCn',
            label: '库存状态'
          },
          {
            prop: 'isCarState',
            label: '车辆状态'
          },
          {
            prop: 'SaleStatus',
            label: '车型销售状态'
          },
          {
            prop: 'hostLimitrEasonCn',
            label: '限制类型'
          },
          {
            prop: 'carLicense',
            label: '车牌号'
          },
          {
            prop: 'cityName',
            label: '交付城市'
          },
          {
            prop: 'ttCode',
            label: '22位码',
            width: 180
          },
          {
            prop: 'carSeriesCode',
            label: '车系编码'
          },
          {
            prop: 'carSeriesCn',
            label: '车系名称'
          },
          {
            prop: 'carConfigCode',
            label: '基础车型编码'
          },
          {
            prop: 'carConfigCn',
            label: '基础车型名称'
          },
          {
            prop: 'optionalPagName',
            label: '选装包'
          },
          {
            prop: 'carColorName',
            label: '车身颜色'
          },
          {
            prop: 'carIncolorName',
            label: '内饰颜色'
          },
          {
            prop: 'carStockHouseName',
            label: '入库仓库'
          },
          {
            prop: 'creator',
            label: '入库人名称'
          },
          {
            prop: 'FirstInDlrstockDate',
            label: '门店入库时间'
          },
          {
            prop: 'vehicleStatusName',
            label: '配车状态'
          },
          {
            prop: 'assignDate',
            label: '配车时间'
          }
        ],
      tableComponents:
      this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          .length > 0
        ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
        : [
          {
            compKey: 'compKey1',
            labelName: '车系：',
            codeField: 'carSeriesId',
            oFields: 'carSeriesId,carSeriesCn',
            customObj: {
              api: lov.listOfCarSeries
            },
            component: () => import('@/components/org/commonSelect'),
            type: 'dropdownList',
            isMul: false,
            isMust: true
          },
          {
            compKey: 'compKey2',
            labelName: '基础车型：',
            codeField: 'carConfigId',
            component: () => import('@/components/org/commonSelect'),
            oFields: 'carConfigId,carConfigCn',
            parentFileds: 'value:carSeriesId',
            customObj: {
              listQuery: { carSeriesId: '' },
              api: lov.queryCarType
            },
            type: 'dropdownList',
            isMul: false,
            isMust: true
          },
          {
            compKey: 'compKey3',
            labelName: '选装包：',
            codeField: 'optionalPagId',
            component: () => import('@/components/org/commonSelect'),
            parentFileds: 'value:carConfigId',
            oFields: 'optionalPagId,optionalPagName',
            customObj: {
              api: lov.queryCarOptionalPagLinkMessage,
              listQuery: {
                carConfigId: ''
              }
            },
            type: 'dropdownList',
            isMul: false,
            isMust: true
          },
          {
            compKey: 'compKey4',
            labelName: '车身颜色：',
            codeField: 'carColorId',
            component: () => import('@/components/org/commonSelect'),
            oFields: 'carColorId,carColorName',
            parentFileds: 'value:carConfigId|carSeriesId|optionalPagId',
            customObj: {
              listQuery: {
                carConfigId: '', carSeriesId: '', optionalPagId: ''
              },
              api: lov.queryCarColorLinkMessage
            },
            type: 'dropdownList',
            isMul: false,
            isMust: true
          },
          {
            compKey: 'compKey5',
            labelName: '内饰颜色：',
            codeField: 'carIncolorId',
            component: () => import('@/components/org/commonSelect'),
            oFields: 'carIncolorId,carIncolorName',
            parentFileds: 'value:carConfigId|carSeriesId|optionalPagId',
            customObj: {
              listQuery: {
                carConfigId: '', carSeriesId: '', optionalPagId: ''
              },
              selectType: '1',
              api: lov.queryCarInColorLinkMessage
            },
            type: 'dropdownList',
            isMul: false,
            isMust: false
          },
          {
            compKey: 'compKey14',
            labelName: '22位码：',
            codeField: 'ttCode',
            component: () => import('@/components/org/commonInput'),
            type: 'inputText',
            isMust: false,
            span: 6
          },
          {
            compKey: 'compKey6',
            labelName: 'VIN码：',
            codeField: 'vin',
            component: () => import('@/components/org/commonInput'),
            type: 'inputText',
            isMust: false,
            span: 6
          },
          // 车辆类型
          {
            compKey: 'compKey7',
            labelName: '入库仓库：',
            codeField: 'stockName',
            component: () => import('@/components/ve/carStockHouse'),
            dataToObject: { warehouseId: '1' },
            type: 'dropdownList',
            isMust: false,
            span: 6
          },
          // 交付城市
          {
            compKey: 'compKey8',
            labelName: '库存状态：',
            codeField: 'moveState',
            lookuptype: 'VE0212',
            component: () => import('@/components/org/LookupValue'),
            type: 'dropdownList',
            isMust: false,
            span: 6
          },
          // 销售状态
          {
            compKey: 'compKey9',
            labelName: '入库时间：',
            codeField: 'startTime,endTime',
            component: () => import('@/components/org/datePicker/datePicker'),
            dateType: 'daterange',
            isMust: false,
            span: 6
          },
          // 车牌号
          {
            compKey: 'compKey10',
            labelName: '车辆状态：',
            codeField: 'deliveryDlrId',
            lookuptype: 'VE0207',
            component: () => import('@/components/org/LookupValue'),
            type: 'dropdownList',
            isMust: false,
            span: 6
          },
          // 车系名称
          {
            compKey: 'compKey11',
            labelName: '限制类型：',
            codeField: 'hostLimitrState',
            lookuptype: 'VE1033',
            component: () => import('@/components/org/LookupValue'),
            type: 'dropdownList',
            isMust: false,
            span: 6
          },
          {
            compKey: 'compKey12',
            labelName: '配车状态：',
            codeField: 'assignState',
            component: () => import('@/components/org/commonSelect'),
            oFields: 'AsId,AsText',
            options: [
              { AsId: '1', AsText: '已配车' },
              { AsId: '0', AsText: '待配车' }
            ],
            type: 'dropdownList',
            isMust: false,
            span: 6
          },
          {
            compKey: 'compKey13',
            labelName: '交付城市：',
            codeField: 'cityId',
            component: () => import('@/components/org/commonSelect'),
            oFields: 'cityId,cityName',
            parentFileds: 'value:carConfigId',
            customObj: {
              api: lov.listOfCities
            },
            type: 'dropdownList',
            isMust: false,
            span: 6
          },
          {
            compKey: 'compKey14',
            labelName: '车型销售状态：',
            codeField: 'SaleStatus',
            lookuptype: 'VE1323',
            component: () => import('@/components/org/LookupValue'),
            type: 'dropdownList',
            isMust: false,
            span: 6
          }
        ],
      tableButtons: [
        {
          conmpKey: 'btenKey1',
          type: '',
          size: 'small',
          clickEvent: () => this.export(),
          text: this.$t('sys.button.export'),
          name: 'export',
          position: 'left' // 导出
        },
        {
          conmpKey: 'btenKey1',
          type: 'primary',
          size: 'small',
          text: this.$t('sys.button.query'), // 查询
          name: 'search', // 按钮图标样式
          clickEvent: () => this.queryTable(1),
          position: 'right'
        },
        {
          conmpKey: 'btenKey2',
          type: '',
          size: 'small',
          text: this.$t('sys.button.reset'),
          name: 'reset',
          clickEvent: () => this.reset(),
          position: 'right'
        }
      ],
      formField: this.$utils.getFormField(this, {
        SaleStatus: '',
        carSeriesId: '',
        carConfigId: '',
        optionalPagId: '',
        carColorId: '',
        carIncolorId: '',
        ttCode: '',
        vin: '',
        carStockHouseId: '',
        moveState: '',
        deliveryDlrId: '',
        startTime: '',
        endTime: '',
        hostLimitrState: '',
        assignState: '',
        cityId: '',
        stockId: '',
        stockName: '',
        stockCode: ''
      })
    }
  },
  methods: {
    // 导出
    export() {
      const fileName = this.$utils.fileNameWithTime('库存明细查询.xlsx')
      this.$requestAPI({
        apiUrl: api.exporStockDetailed.APIUrl,
        variables: { ...this.formField, dataType: 'excel' }
      }).then(res => {
        this.$utils.downloadFile(res, fileName)
      }).catch(err => {
        console.info(err)
      })
    }
  }
}
</script>

<style>
</style>
